package cn.itcast.oa.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.oa.base.BaseDaoImpl;
import cn.itcast.oa.dao.DepartmentDao;
import cn.itcast.oa.domain.Department;
import cn.itcast.oa.service.DepartmentService;

@Service("departmentService")
@Transactional
public class DepartmentServiceImpl extends BaseDaoImpl<Department> implements DepartmentService{
 
//	@Resource
//	private DepartmentDao departmentDao ;
//	
	@Resource
	private SessionFactory sessionFactory ;    
//	
//	
//	public List<Department> findAll() {
//		return departmentDao.findAll();
//	}
//	
//	public void save(Department department) {
//		departmentDao.save(department);
//		
//	}
//
//	public Department getById(Long id) {
//		
//		return departmentDao.getById(id);
//	}
//
//	public void update(Department model) {
//		departmentDao.update(model);
//	}
//
//	public void delete(Long id) {
//		departmentDao.delete(id);
//		
//	}

	
	/**
	 * 查询子部门列表
	 */
	public List<Department> findChildren(Long parentId) {
		return sessionFactory.getCurrentSession().createQuery(//
				"FROM Department d WHERE d.parent.id=?")//
				.setParameter(0, parentId)//
				.list();
	}
	/**
	 * 查询顶级部门列表
	 */
	public List<Department> findTopList() {
		return sessionFactory.getCurrentSession().createQuery(//
				"FROM Department d WHERE d.parent IS NULL "//
				).list();
	}
	

}
